//------------------------------------------------------------------------------
// @description 管理员端-基础工作-已结束-详情
//------------------------------------------------------------------------------
<script setup name="BseWorkFinishDetail">
//------------------------------------------------------------------------------
// 模块导入
//------------------------------------------------------------------------------
import { ref,watchEffect } from 'vue'
import { useRouter } from 'vue-router';

import {Close} from '@element-plus/icons-vue'
import service from '@/utils/request';
//------------------------------------------------------------------------------
// 数据存储
//------------------------------------------------------------------------------
const router = useRouter();
const routerQuery = router.currentRoute.value.query;

//学生学业情况数据
const studentStudyData = ref({
    //基本要求
    baseRequirementScore: "",
    baseRequirementImg: [],
    baseRequirementWord: [],
    //学生思想引领
    thoughtGuidanceScore: "",
    thoughtGuidanceImg: [],
    thoughtGuidanceWord: [],
    //学生学业规划
    studyPlanScore: "",
    studyPlanImg: [],
    studyPlanWord: [],
    //学生职业规划
    careerPlanScore: "",
    careerPlanImg: [],
    careerPlanWord: [],
    //学生科研成果
    scientificResultScore: "",
    scientificResultImg: [],
    scientificResultWord: [],
    //分数合计
    totalScore: ""
})
//记录总分
watchEffect(() => {
    studentStudyData.value.totalScore = 0;
    studentStudyData.value.totalScore += Number(studentStudyData.value.baseRequirementScore) || 0;
    studentStudyData.value.totalScore += Number(studentStudyData.value.thoughtGuidanceScore) || 0;
    studentStudyData.value.totalScore += Number(studentStudyData.value.studyPlanScore) || 0;
    studentStudyData.value.totalScore += Number(studentStudyData.value.careerPlanScore) || 0;
    studentStudyData.value.totalScore += Number(studentStudyData.value.scientificResultScore) || 0;
})
//图片预览相关
const isShowPreviewImg = ref(false);
const previewImgData = ref('');


//------------------------------------------------------------------------------
// 数据处理方法
//------------------------------------------------------------------------------
const fixedStudentStudyData = (data) => {
    // 关键：先给所有需要调用filter的字段设置默认空数组，避免undefined
    const basicRequirement = data?.basicRequirement || []; // 用?.判断data是否存在，再给默认值
    const studentThought = data?.studentThought || [];
    const academicPlanning = data?.academicPlanning || [];
    const careerPlanning = data?.careerPlanning || [];
    const researchAchievement = data?.researchAchievement || [];
    return {
        // 基本要求
        baseRequirementScore: data?.scoreBasicRequirement || "",
        baseRequirementImg: basicRequirement.filter(item => {
            return !item.includes(".doc") && !item.includes(".docx"); // 简化filter逻辑，无需if包裹
        }),
        baseRequirementWord: basicRequirement.filter(item => {
            return item.includes(".doc") || item.includes(".docx");
        }),
        // 学生思想引领
        thoughtGuidanceScore: data?.scoreStudentThought || "",
        thoughtGuidanceImg: studentThought.filter(item => {
            return !item.includes(".doc") && !item.includes(".docx");
        }),
        thoughtGuidanceWord: studentThought.filter(item => {
            return item.includes(".doc") || item.includes(".docx");
        }),
        // 学生学业规划
        studyPlanScore: data?.scoreAcademicPlanning || "",
        studyPlanImg: academicPlanning.filter(item => {
            return !item.includes(".doc") && !item.includes(".docx");
        }),
        studyPlanWord: academicPlanning.filter(item => {
            return item.includes(".doc") || item.includes(".docx");
        }),
        // 学生职业规划（补充之前遗漏的careerPlanWord）
        careerPlanScore: data?.scoreCareerPlanning || "",
        careerPlanImg: careerPlanning.filter(item => {
            return !item.includes(".doc") && !item.includes(".docx");
        }),
        careerPlanWord: careerPlanning.filter(item => {
            return item.includes(".doc") || item.includes(".docx");
        }),
        // 学生科研成果（补充完整filter逻辑）
        scientificResultScore: data?.scoreResearchAchievement || "",
        scientificResultImg: researchAchievement.filter(item => {
            return !item.includes(".doc") && !item.includes(".docx");
        }),
        scientificResultWord: researchAchievement.filter(item => {
            return item.includes(".doc") || item.includes(".docx");
        }),
        // 分数合计
        totalScore: data?.totalScore || ""
    }
}
const getStudentStudyData = () => {
    service({
        method: "get",
        url: "/admin/teacherbaseworkdetail",
        headers:{
            Authorization: localStorage.getItem('token'),
        },
        params: {
            questionnaireId: routerQuery.taskId,
            teacherName: routerQuery.name,
            teacherId: routerQuery.teacherId,
            questionnairename: routerQuery.taskName
        }
    }).then((res) => {
        studentStudyData.value = fixedStudentStudyData(res.data.data);
    })
}
getStudentStudyData();


//点击下载word文档
const downloadWord = (url) => {
    url.forEach((item) => {
        const elink = document.createElement('a');
        document.body.appendChild(elink);
        elink.style.display = 'none';
        elink.href = item;
        elink.click();
        document.body.removeChild(elink);
    })
}

//点击预览图片
const previewImgClick = (url) => {
    previewImgData.value = url;
    isShowPreviewImg.value = true;
}


</script>

<template>
    <!-- 预览图片 -->
    <div class="imgPreview" v-show="isShowPreviewImg" @click="isShowPreviewImg = false">
        <div class="imgContent">
            <span class="close" @click="isShowPreviewImg = false">
                <el-icon><Close /></el-icon>
            </span>
            <img :src="previewImgData" alt="">            
        </div>
    </div>

    <!-- //组件内容 -->
    <div class="bseWorkFinishDetail">
        <div class="header">
            <span @click="router.push({
            path: '/administrator/finish',
            query: {
                    state:'已结束'
                }
            })">任务列表</span>
            <span>/基础情况详情</span>
        </div>
        <!-- 填写部分 -->
        <div class="layout">
            <div class="layoutHeader">学业情况详情</div>
            <div class="layoutContent">
                <!-- 基本信息栏 -->
                <div class="baseInfo">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>基本信息</div>
                    </div>
                    <div class="content">
                        <div class="item">
                            <span>教师姓名</span>
                            <span>{{ routerQuery.name }}</span>
                        </div>
                        <div class="item">
                            <span>工号</span>
                            <span>{{ routerQuery.id }}</span>
                        </div>
                        <div class="item">
                            <span>任务名称</span>
                            <span>{{ routerQuery.taskName }}</span>
                        </div>
                        <div class="item">
                            <span>任务状态</span>
                            <span>{{ routerQuery.taskState }}</span>
                        </div>
                    </div>
                </div>
                <!-- 5个打分部分 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>基本要求</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="studentStudyData.baseRequirementImg.length > 0 || studentStudyData.baseRequirementWord.length > 0">
                                <div class="img" v-if="studentStudyData.baseRequirementImg.length > 0">
                                    <img  v-for="item in studentStudyData.baseRequirementImg" :src="item" alt="" @click="previewImgClick(item)">                              
                                </div>
                                <div class="download" @click="downloadWord(studentStudyData.baseRequirementWord)" v-if="studentStudyData.baseRequirementWord.length > 0">下载word材料</div>                                
                            </div>
                            <div v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span>{{ studentStudyData.baseRequirementScore }}</span>
                        </div>
                    </div>
                </div>
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生思想引领</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="studentStudyData.thoughtGuidanceImg.length > 0 || studentStudyData.thoughtGuidanceWord.length > 0">
                                <div class="img" v-if="studentStudyData.thoughtGuidanceImg.length > 0">
                                    <img  v-for="item in studentStudyData.thoughtGuidanceImg" :src="item" alt="" @click="previewImgClick(item)">                              
                                </div>
                                <div class="download" @click="downloadWord(studentStudyData.thoughtGuidanceWord)" v-if="studentStudyData.thoughtGuidanceWord.length > 0">下载word材料</div>                                
                            </div>
                            <div v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span>{{ studentStudyData.thoughtGuidanceScore }}</span>
                        </div>
                    </div>
                </div>
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生学业规划</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="studentStudyData.studyPlanImg.length > 0 || studentStudyData.studyPlanWord.length > 0">
                                <div class="img" v-if="studentStudyData.studyPlanImg.length > 0">
                                    <img  v-for="item in studentStudyData.studyPlanImg" :src="item" alt="" @click="previewImgClick(item)">                              
                                </div>
                                <div class="download" @click="downloadWord(studentStudyData.studyPlanWord)" v-if="studentStudyData.studyPlanWord.length > 0">下载word材料</div>                                
                            </div>
                            <div v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span>{{ studentStudyData.studyPlanScore }}</span>
                        </div>
                    </div>
                </div>
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生职业规划</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="studentStudyData.careerPlanImg.length > 0 || studentStudyData.careerPlanWord.length > 0">
                                <div class="img" v-if="studentStudyData.careerPlanImg.length > 0">
                                    <img  v-for="item in studentStudyData.careerPlanImg" :src="item" alt="" @click="previewImgClick(item)">                              
                                </div>
                                <div class="download" @click="downloadWord(studentStudyData.careerPlanWord)" v-if="studentStudyData.careerPlanWord.length > 0">下载word材料</div>                                
                            </div>
                            <div v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span>{{ studentStudyData.careerPlanScore }}</span>
                        </div>
                    </div>
                </div>
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生科研成果</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="studentStudyData.scientificResultImg.length > 0 || studentStudyData.scientificResultWord.length > 0">
                                <div class="img" v-if="studentStudyData.scientificResultImg.length > 0">
                                    <img  v-for="item in studentStudyData.scientificResultImg" :src="item" alt="" @click="previewImgClick(item)">                              
                                </div>
                                <div class="download" @click="downloadWord(studentStudyData.scientificResultWord)" v-if="studentStudyData.scientificResultWord.length > 0">下载word材料</div>                                
                            </div>
                            <div v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span>{{ studentStudyData.scientificResultScore }}</span>
                        </div>
                    </div>
                </div>
                <!-- 分数合计部分 -->
                <div class="totalScore">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>分数合计</div>
                    </div>
                    <div class="content">
                        <div class="item">
                            <span class="score">分数合计</span>
                            <span>{{ studentStudyData.totalScore }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
//预览图片
.imgPreview{
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    .imgContent{
        position: relative;
        .close{
            position: absolute;
            top: 10px;
            right: 10px;
            cursor: pointer;
            font-size: 20px;
            &:hover{
                color: red;
            }
        }
    }
}


.bseWorkFinishDetail {
    width: 100%;
    height: 100%;
    font-weight: 500;
    .header{
        width: 100%;
        height: 10%;
        padding-left: 15px;
        display: flex;
        align-items: center;
        color:#7f7f7f;
        border-top: 1px solid;
        border-bottom: 1px solid;
        span:hover{
            color:#4c5fbc;
            font-weight: 600;
        }
    }
    .layout{
        width: 100%;
        height: 90%;
        padding: 0 70px;
        display: flex;
        flex-direction: column;
        align-items: center;
        .layoutHeader{
            width: 100%;
            margin-top: 40px;
            font-size: 20px;
        }
        .layoutContent{
            width: 100%;
            height: 85%;
            margin-top: 10px;
            margin-bottom: 10px;
            color:#7a838f;
            overflow: auto;
            &::-webkit-scrollbar{
                display: none;
            }
            .baseInfo{
                width: 100%;
                padding: 20px 15px;
                background-color: #fff;
                border-radius: 5px;
                font-size: 15px;
                .contentHeader{
                    width: 100%;
                    height: 25px;
                    display: flex;
                    align-items: center;
                    gap: 10px;
                    font-size: 18px;
                    color:#000;
                    .line{
                        width: 5px;
                        height: 18px;
                        background-color: #4c5fbc;
                    }
                }
                .content{
                    width: 100%;
                    height: calc(100% - 25px);
                    display: flex;
                    flex-wrap: wrap;
                    padding: 0 20px;
                    .item{
                        width: 33%;
                        height: fit-content;
                        margin-top: 10px;
                        display: flex;
                        align-items: center;
                        gap:10px;
                        overflow: hidden;
                    }
                }
            }
            .markContent{
                width: 100%;
                margin-top: 40px;
                padding: 20px 15px;
                background-color: #fff;
                border-radius: 5px;
                .contentHeader{
                    width: 100%;
                    height: 25px;
                    display: flex;
                    align-items: center;
                    gap: 10px;
                    font-size: 18px;
                    color:#000;
                    .line{
                        width: 5px;
                        height: 18px;
                        background-color: #4c5fbc;
                    }
                }
                .content{
                    width: 100%;
                    height: calc(100% - 25px);
                    padding: 0 20px;
                    .proveItem{
                        width: 100%;
                        margin-top: 30px;
                        display: flex;
                        gap: 40px;
                        .title{
                            width: 70px;
                            height: 30px;
                            line-height: 30px;
                            text-align: right;
                            white-space: nowrap;
                        }
                        .proveItemContent{
                            width: calc(100% - 70px);
                            .img{
                                width: 100%;
                                display: flex;
                                gap:10px;
                                img{
                                    width: 100px;
                                    height: 150px;
                                }
                            }
                            .download{
                                width: 100px;
                                height: 25px;
                                margin-top: 5px;
                                text-align: center;
                                line-height: 25px;
                                background-color: #f4f4f5;
                                border: 1px solid #909399;
                                border-radius: 3px;
                                color:#909399;
                                font-size: 14px;
                                cursor: pointer;
                                &:hover{
                                    background-color: #f4f4f5d2;
                                    color:#909399d2;
                                }
                            }                          
                        }
                    }
                    .scoreItem{
                        width: 100%;
                        margin-top: 30px;
                        display: flex;
                        align-items: center;
                        gap: 40px;
                        .title{
                            text-align: right;
                            width: 70px;
                            white-space: nowrap;
                        }
                        input{
                            width: 200px;
                            height: 30px;
                            outline: none;
                            border: none;
                            border-radius: 5px;
                            background-color: #e5e6eb;
                            color:#86909c;
                            text-indent: 10px;
                            font-size: 15px;
                            &:hover{
                                background-color: #e5e6ebd2;
                            }
                            &:focus{
                                outline: 1px solid #4c5fbc;
                                background-color: #e5e6ebd2;
                            }
                        }
                    }
                }
            }
            .totalScore{
                width: 100%;
                margin-top: 40px;
                padding: 20px 15px;
                background-color: #fff;
                border-radius: 5px;
                font-size: 15px;
                .contentHeader{
                    width: 100%;
                    height: 25px;
                    display: flex;
                    align-items: center;
                    gap: 10px;
                    font-size: 18px;
                    color:#000;
                    .line{
                        width: 5px;
                        height: 18px;
                        background-color: #4c5fbc;
                    }
                }
                .content{
                    width: 100%;
                    height: calc(100% - 25px);
                    display: flex;
                    flex-wrap: wrap;
                    padding: 0 40px;
                    .item{
                        margin-top: 10px;
                        display: flex;
                        align-items: center;
                        gap:30px;
                        overflow: hidden;
                        input{
                            width: 200px;
                            height: 30px;
                            outline: none;
                            border: none;
                            border-radius: 5px;
                            background-color: #e5e6eb;
                            color:#86909c;
                            text-indent: 10px;
                            font-size: 15px;
                            &:hover{
                                background-color: #e5e6ebd2;
                            }
                            &:focus{
                                border: 1px solid #4c5fbc;
                                background-color: #e5e6ebd2;
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>